package com.minicrm.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.minicrm.common.annotation.Log;
import com.minicrm.common.enums.BusinessType;
import com.minicrm.system.domain.Returning;
import com.minicrm.system.service.IReturningService;
import com.minicrm.common.core.controller.BaseController;
import com.minicrm.common.core.domain.AjaxResult;
import com.minicrm.common.utils.poi.ExcelUtil;
import com.minicrm.common.core.page.TableDataInfo;

/**
 * returningController
 * 
 * @author minicrm
 * @date 2022-03-21
 */
@Controller
@RequestMapping("/system/returning")
public class ReturningController extends BaseController
{
    private String prefix = "system/returning";

    @Autowired
    private IReturningService returningService;

    @RequiresPermissions("system:returning:view")
    @GetMapping()
    public String returning()
    {
        return prefix + "/returning";
    }

    /**
     * 查询returning列表
     */
    @RequiresPermissions("system:returning:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Returning returning)
    {
        startPage();
        List<Returning> list = returningService.selectReturningList(returning);
        return getDataTable(list);
    }

    /**
     * 导出returning列表
     */
    @RequiresPermissions("system:returning:export")
    @Log(title = "returning", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Returning returning)
    {
        List<Returning> list = returningService.selectReturningList(returning);
        ExcelUtil<Returning> util = new ExcelUtil<Returning>(Returning.class);
        return util.exportExcel(list, "returning数据");
    }

    /**
     * 新增returning
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存returning
     */
    @RequiresPermissions("system:returning:add")
    @Log(title = "returning", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Returning returning)
    {
        return toAjax(returningService.insertReturning(returning));
    }

    /**
     * 修改returning
     */
    @RequiresPermissions("system:returning:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Returning returning = returningService.selectReturningById(id);
        mmap.put("returning", returning);
        return prefix + "/edit";
    }

    /**
     * 修改保存returning
     */
    @RequiresPermissions("system:returning:edit")
    @Log(title = "returning", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Returning returning)
    {
        return toAjax(returningService.updateReturning(returning));
    }

    /**
     * 删除returning
     */
    @RequiresPermissions("system:returning:remove")
    @Log(title = "returning", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(returningService.deleteReturningByIds(ids));
    }
}
